<?php
$ngay=date("Y-m-d");
$sql=mysql_query("select sanpham.masp,sanpham.tensp,sanpham.hinhanh,khuyenmai.hinhthuckm from sanpham,khuyenmai where tungay<='$ngay' && denngay>='$ngay' && trangthai=1 && sanpham.masp=khuyenmai.masp");
$num=mysql_num_rows($sql);
if($num!=0){
	include("templates/khuyenmai.html");
}
echo "&nbsp;<br>";
$result=mysql_query("select masp,tensp,giaban,hinhanh from sanpham");
	$t=mysql_num_rows($result);
echo "<table width=100% cellpadding=\"0\" cellspacing=\"0\" class=\"box\"><tr><td>";

	echo "<table width=100% cellpadding=\"0\" cellspacing=\"0\">";
	echo "<tr><td width=\"1%\" height=\"20\" background=\"images/main_left.gif\">&nbsp;</td>
      <td width=\"99%\" background=\"images/main.gif\" class=\"tieude\"><img src=\"images/abu061.gif\" width=\"16\" height=\"9\" />&nbsp;DANH SÁCH SẢN PHẨM </td></tr></table>";
if($t!=0){
	 echo "<table width=100% class='main'>";
	$i=1;
	echo "<tr >";	
	while(($row=mysql_fetch_row($result))&&($i<=$t)){
			$i++;	
			$sql=mysql_query("select* from theodoisp where masp='$row[0]'");
			$sl=mysql_fetch_array($sql);
			if($sl[slhiencon]==0){
				$hiencon='Đã hết hàng trong kho';
				}else{
					$hiencon="Hiện còn: ".$sl[slhiencon]." chiếc";
				}
			echo "<td width='50%'  align='center'><table width=100% cellpadding=\"4\" cellspacing=\"4\" class=\"sanpham\"><tr valign='top'><td align='center' width='30%' height='125'><a href=index.php?page=sanpham&&act=chitiet&&masp=$row[0]><img src='images/sanpham/".$row[3]."' border='0'></a><br><a href=index.php?page=sanpham&&act=chitiet&&masp=$row[0]>Xem chi tiết </a></td><td align='left'><a href=index.php?page=sanpham&&act=chitiet&&masp=$row[0]><b>".ucfirst($row[1])."</b></a><br> Giá:".$row[2]." VND<br><b>".$hiencon."</b><br><br><br><br><div align='center'><a href=index.php?page=giohang&&act=mua&&masp=$row[0]><img src=\"images/buy_now.gif\" border='0'></a></div></td></tr></table></td>";
	
		if($i%2) echo "</tr>";
		}
echo "</table>";
}
echo "</td></tr></table>";
?>